﻿@inject NetCoreCMS.IServices.IUsersService  _users
@{
    Layout = null;
    Sysconfig config = ViewData["config"] as Sysconfig;
    string action = ViewBag.action as string;
    List<User_message> messageList = (List<User_message>)ViewBag.messageList;
}
<!DOCTYPE html>
<!--HTML5 doctype-->
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <title>站内短信息</title>
    <link rel="stylesheet" type="text/css" href="/mobile/css/style.css" />
    <script type="text/javascript" charset="utf-8" src="/mobile/js/zepto.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="/mobile/js/weui.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="/mobile/js/common.js"></script>
    <script type="text/javascript">
        function ExecPostBack(checkValue) {
            if (arguments.length == 1) {
                ExecDelete('/submit_ajax?action=user_message_delete', checkValue, '#turl');
            } else {
                var valueArr = '';
                $("input[name='checkId']:checked").each(function (i) {
                    valueArr += $(this).val();
                    if (i < $("input[name='checkId']:checked").length - 1) {
                        valueArr += ","
                    }
                });
                ExecDelete('/submit_ajax?action=user_message_delete', valueArr, '#turl');
            }
        }
    </script>
</head>

<body ontouchstart>
    <div class="page">
        <!--页面头部-->
        <div class="header">
            <a class="back" href="javascript:history.back();">
                <i class="iconfont icon-arrow-left"></i>
            </a>
            <h3>站内短消息</h3>
            <div class="right">
                <a class="weui-cell_access weui-cell_link" asp-area="Web" asp-controller="Usercenter" asp-action="Index" asp-route-act="index">
                    <i class="iconfont icon-user"></i>
                </a>
            </div>
        </div>
        <!--/页面头部-->

        <div class="page__bd">

            @if(action=="add")
            {
            <!--发送消息-->
            <link rel="stylesheet" type="text/css" href="/mobile/css/validate.css" />
            <script type="text/javascript" charset="utf-8" src="/mobile/js/mvalidate.js"></script>
            <script type="text/javascript" charset="utf-8" src="/mobile/js/mvalidate-extend.js"></script>
            <script type="text/javascript">
                $(function () {
                    //初始化表单
                    AjaxInitForm('#addForm', '#btnSubmit', 1, '#turl');
                    //选中TAB样式
                    $(".weui-tabbar a").eq(0).addClass("weui-bar__item_on");
                });
            </script>
            <form id="addForm" name="addForm" url="/submit_ajax?action=user_message_add">
                <div class="weui-panel weui-panel_access" style="margin-top:10px;">
                    <div class="weui-panel__hd">发送消息</div>
                    <div class="weui-panel__bd">
                        <div class="weui-cells_form form-box">
                            <div class="weui-cell">
                                <div class="weui-cell__hd">
                                    <label class="weui-label">收件人</label>
                                </div>
                                <div class="weui-cell__bd">
                                    <input id="txtUserName" name="txtUserName" class="weui-input" type="text" placeholder="收件人用户名" data-validate="username" />
                                </div>
                            </div>
                            <div class="weui-cell">
                                <div class="weui-cell__hd">
                                    <label class="weui-label">标题</label>
                                </div>
                                <div class="weui-cell__bd">
                                    <input id="txtTitle" name="txtTitle" class="weui-input" type="text" placeholder="请输入标题" data-validate="s" />
                                </div>
                            </div>
                            <div class="weui-cell">
                                <div class="weui-cell__bd">
                                    <textarea name="txtContent" class="weui-textarea" placeholder="请输入内容" rows="3"></textarea>
                                </div>
                            </div>
                            <div class="weui-cell">
                                <div class="weui-cell__hd">
                                    <label class="weui-label">验证码</label>
                                </div>
                                <div class="weui-cell__bd">
                                    <input id="txtCode" name="txtCode" class="weui-input" type="text" placeholder="请输入验证码" data-validate="code" />
                                </div>
                                <div class="weui-cell__ft">
                                    <a href="javascript:;" onclick="ToggleCode(this, '/verify_code/index');return false;">
                                        <img class="weui-vcode-img" src="/verify_code/index" style="width:82px;height:24px;" />
                                    </a>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="weui-panel weui-panel_access">
                    <div class="weui-panel__bd">
                        <div class="weui-cells_form form-box">
                            <div class="weui-cell weui-cell_switch">
                                <div class="weui-cell__bd">保存到发件箱</div>
                                <div class="weui-cell__ft">
                                    <input id="sendSave" name="sendSave" type="checkbox" class="weui-switch" value="true" checked="checked" />
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="weui-btn-area">
                    <input id="btnSubmit" name="btnSubmit" type="submit" class="weui-btn weui-btn_primary" value="确认发送" />
                </div>
            </form>
            <!--发送消息-->
            }
            else if(action=="system")
            {
            <!--系统消息-->
            <script type="text/javascript">
                $(function () {
                    //选中TAB样式
                    $(".weui-tabbar a").eq(1).addClass("weui-bar__item_on");
                });
            </script>

            <div class="detail-list">
                <ul>                    
                    <!--取得分页页码列表-->                   
                    @foreach(User_message dr in messageList)
                    {
                    <li>
                        <div class="detail-bd">
                            <div class="list-box">
                                <div class="txt-box">
                                    <h2>@dr.title</h2>
                                    <p class="note">
                                        <span class="fr">
                                            @if(dr.is_read==1)
                                            {
                                            @:已读
                                            }
                                            else
                                            {
                                            @:未读
                                            }
                                        </span>
                                        <span>@dr.post_time</span>
                                    </p>
                                </div>
                            </div>
                        </div>
                        <div class="detail-ft">
                            <div class="ft-btn">
                                <div class="btn-box">
                                    <a asp-action="Show" asp-route-id="@dr.id">查看详情</a>
                                    <a href="javascript:;" onclick="ExecPostBack('@dr.id');">
                                        <i class="iconfont icon-delete"></i>
                                        删除
                                    </a>
                                </div>
                            </div>
                        </div>
                    </li>
                    }
                    @if(messageList.Count==0)
                    {
                    <div class="nodata">暂无记录...</div>
                    }
                </ul>
            </div>

            <!--分页页码-->
        <div class="page-list">
            @Html.Raw(ViewBag.pagelist)
        </div>
            <!--/分页页码-->

        <input id="turl" type="hidden" value="/Web/Usermessage/Index?action=system" /><!--存在跳转的URL值-->
            <!--/系统消息-->
            }
            else if(action=="accept")
            {
            <!--收件箱-->
            <script type="text/javascript">
                $(function () {
                    //选中TAB样式
                    $(".weui-tabbar a").eq(2).addClass("weui-bar__item_on");
                });
            </script>

            <div class="detail-list">
                <ul>                  
                    <!--取得分页页码列表-->
                    @foreach(User_message dr in messageList)
                    {
                    <li>
                        <div class="detail-bd">
                            <div class="list-box">
                                <div class="img-box">
                                    @{
                                        var post_user = _users.GetModel(dr.post_user_name);
                                        string user_avatar = "";
                                        if (post_user != null)
                                            user_avatar = post_user.avatar;
                                    }
                                    @if(string.IsNullOrEmpty(user_avatar))
                                    {
                                    <i class="iconfont icon-user-full"></i>
                                    }
                                    else
                                    {
                                    <img src="@user_avatar" alt="@dr.post_user_name" />
                                    }
                                </div>
                                <div class="txt-box">
                                    <h2>@dr.title</h2>
                                    <p>发件人 @dr.post_user_name</p>
                                    <p class="note">
                                        <span class="fr">
                                            @if(dr.is_read==1)
                                            {
                                            @:已读
                                            }
                                            else
                                            {
                                            @:未读
                                            }
                                        </span>
                                        <span>@dr.post_time</span>
                                    </p>
                                </div>
                            </div>
                        </div>
                        <div class="detail-ft">
                            <div class="ft-btn">
                                <div class="btn-box">
                                    <a asp-action="Show" asp-route-id="@dr.id">查看详情</a>
                                    <a href="javascript:;" onclick="ExecPostBack('@dr.id');">
                                        <i class="iconfont icon-delete"></i>
                                        删除
                                    </a>
                                </div>
                            </div>
                        </div>
                    </li>
                    }
                    @if(messageList.Count==0)
                    {
                    <div class="nodata">暂无记录...</div>
                    }
                </ul>
            </div>

            <!--分页页码-->
        <div class="page-list">
            @Html.Raw(ViewBag.pagelist)
        </div>
            <!--/分页页码-->

        <input id="turl" type="hidden" value="/Web/Usermessage/Index?action=accept" /><!--存在跳转的URL值-->
            <!--/收件箱-->
            }
            else if(action=="send")
            {
            <!--发件箱-->
            <script type="text/javascript">
                $(function () {
                    //选中TAB样式
                    $(".weui-tabbar a").eq(3).addClass("weui-bar__item_on");
                });
            </script>

            <div class="detail-list">
                <ul>
                    <!--取得分页页码列表-->
                    @foreach(User_message dr in messageList)
                    {
                    <li>
                        <div class="detail-bd">
                            <div class="list-box">
                                <div class="img-box">
                                    @{ 
                                        var accept_user = _users.GetModel(dr.accept_user_name);
                                        string user_avatar = "";
                                        if (accept_user != null)
                                            user_avatar = accept_user.avatar;
                                    }
                                    @if(string.IsNullOrEmpty(user_avatar))
                                    {
                                    <i class="iconfont icon-user-full"></i>
                                    }
                                    else
                                    {
                                    <img src="@user_avatar" alt="@dr.post_user_name" />
                                    }
                                </div>
                                <div class="txt-box">
                                    <h2>@dr.title</h2>
                                    <p>收件人 @dr.accept_user_name</p>
                                    <p>@dr.post_time</p>
                                </div>
                            </div>
                        </div>
                        <div class="detail-ft">
                            <div class="ft-btn">
                                <div class="btn-box">
                                    <a asp-action="Show" asp-route-id="@dr.id">查看详情</a>
                                    <a href="javascript:;" onclick="ExecPostBack('@dr.id');">
                                        <i class="iconfont icon-delete"></i>
                                        删除
                                    </a>
                                </div>
                            </div>
                        </div>
                    </li>
                    }
                    @if(messageList.Count==0)
                    {
                    <div class="nodata">暂无记录...</div>
                    }
                </ul>
            </div>

            <!--分页页码-->
            <div class="page-list">
                @Html.Raw(ViewBag.pagelist)
            </div>
            <!--/分页页码-->

            <input id="turl" type="hidden" value="/Web/Usermessage/Index?action=send" /><!--存在跳转的URL值-->
            <!--/发件箱-->
            }

        </div>

        <!--版权信息-->
        @await Html.PartialAsync("~/Areas/Web/Views/Shared/_Copyright.cshtml")
        <!--/版权信息-->
        <!--底部导航-->
        <div class="weui-tab foot-nav">
            <div class="weui-tab__panel">

            </div>
            <div class="weui-tabbar">
                <a asp-area="Web" asp-controller="Usermessage" asp-action="Index" asp-route-act="add" class="weui-tabbar__item">
                    <i class="iconfont icon-edit weui-tabbar__icon"></i>
                    <p class="weui-tabbar__label">发送消息</p>
                </a>
                <a asp-area="Web" asp-controller="Usermessage" asp-action="Index" asp-route-act="system" class="weui-tabbar__item">
                    <i class="iconfont icon-notice weui-tabbar__icon"></i>
                    <p class="weui-tabbar__label">系统消息</p>
                </a>
                <a asp-area="Web" asp-controller="Usermessage" asp-action="Index" asp-route-act="accept" class="weui-tabbar__item">
                    <i class="iconfont icon-folder weui-tabbar__icon"></i>
                    <p class="weui-tabbar__label">收件箱</p>
                </a>
                <a asp-area="Web" asp-controller="Usermessage" asp-action="Index" asp-route-act="send" class="weui-tabbar__item">
                    <i class="iconfont icon-log weui-tabbar__icon"></i>
                    <p class="weui-tabbar__label">发件箱</p>
                </a>
            </div>
        </div>
        <!--/底部导航-->
    </div>
</body>
</html>
